home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / wdraw.pro < prev    next >
Text File  |  1997-07-08  |  5KB  |  181 lines

  1. ; $Id: wdraw.pro,v 1.3 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This is the code for a simple DRAW widget.  It displays
  7. ; an image of a "DIST" and allows the user to erase the
  8. ; draw widget and to redraw the image.  If the mouse button
  9. ; is pressed while the cursor is moved over the displayed 
  10. ; image, the X and Y positions of the cursor are printed in
  11. ; the IDL window.
  12.  
  13. ; Draw widgets are very similar to IDL graphics windows.
  14.  
  15. ; For an example of a draw widget with scroll bars, 
  16. ; see the procedure WDR_SCRL.PRO.
  17.  
  18. PRO wdraw_event, event
  19. ; This is the event handler for a simple draw widget.
  20.  
  21. ; The COMMON block is used because the event handler usually needs
  22. ; the window number and the size of the draw widget:
  23.  
  24. COMMON wdrawblock, win_num, orig_image, x_im_sz, y_im_sz
  25.  
  26. ; When a widget is manipulated, put its User Value into the variable 'eventval':
  27.  
  28. WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  29.  
  30. ; Perform actions based on the User Value of the event:
  31. CASE eventval OF
  32.    'DRAW_WIN_EVENT': BEGIN
  33.             ; The help statement is useful for
  34.             ; debugging the event handler.  Try uncommenting
  35.             ; it to see the full structure returned by a 
  36.             ; draw window event.  Note the 'PRESS' and
  37.             ; 'RELEASE' fields.
  38.             ; HELP, /STRUCT, event
  39.  
  40.             ; Only deal with the 'press' event,
  41.             ; disregard the 'release' event
  42.             IF event.press EQ 1 THEN BEGIN
  43.                 ; Print the device coordinates of the cursor
  44.                 PRINT, 'X = ', event.x
  45.                 PRINT, 'Y = ', event.y
  46.             ENDIF
  47.              END
  48.  
  49.    'ERASE': BEGIN
  50.         swin = !D.WINDOW        ; Save previous window
  51.         ; Set the window number - important for multiple windows
  52.         WSET, win_num                
  53.                 ERASE                   ; Erase the image
  54.         WSET, swin              ; Restore previous window
  55.              END
  56.  
  57.    'REDRAW': BEGIN
  58.         swin = !D.WINDOW        ; Save previous window
  59.         ; Set the window number - important for multiple windows
  60.         WSET, win_num
  61.                 ; Redraw the image
  62.                 TVSCL, REBIN(orig_image, x_im_sz, y_im_sz)
  63.         WSET, swin              ; Restore previous window
  64.              END
  65.  
  66.    'DONE': BEGIN
  67.                 WIDGET_CONTROL, event.top, /DESTROY
  68.            END
  69. ENDCASE
  70.  
  71. END
  72.  
  73.  
  74.  
  75. PRO wdraw, XSIZE=x_size, YSIZE=y_size, GROUP=GROUP
  76.  
  77. ; This is the procedure that creates a draw widget.
  78.  
  79. ; The COMMON block is used because the event handler usually needs
  80. ; the window number and the size of the draw widget.
  81. ; Names of common variables must be distinct from keyword variables.
  82. COMMON wdrawblock, win_num, orig_image, x_im_sz, y_im_sz
  83.  
  84. swin = !D.WINDOW    ; Remember the current window so it can be restored
  85.  
  86. ; The size of the draw area is one of the more important parameters
  87. ; for a draw widget.  This example uses keywords to define the size
  88. ; of the draw area.  An alternative would be to use a fixed size draw area. 
  89. if (NOT keyword_set(x_size)) THEN x_size = 400
  90. if (NOT keyword_set(y_size)) THEN y_size = 500
  91.  
  92. ; A top-level base widget with the title "Simple Draw Widget Example"
  93. ; will be created.  The size is left unspecified until the draw widget
  94. ; is created.
  95.  
  96. base = WIDGET_BASE(TITLE = 'Simple Draw Widget Example', $
  97.     /COLUMN)
  98.  
  99. ; Setting the managed attribute indicates our intention to put this application
  100. ; under the control of XMANAGER, and prevents our draw widgets from
  101. ; becoming candidates for becoming the default window on WSET, -1. XMANAGER
  102. ; sets this, but doing it here prevents our own WSETs at startup from
  103. ; having that problem.
  104. WIDGET_CONTROL, /MANAGED, base
  105.  
  106. ; The DONE button:
  107. button1 = WIDGET_BUTTON(base, $
  108.         UVALUE = 'DONE', $
  109.         VALUE = 'DONE')
  110.  
  111. ; A label containing some instructions:
  112. wdrlabel = WIDGET_LABEL(base, $
  113.        VALUE = 'Press the left mouse button to see cursor coordinates.')
  114.  
  115. ; A widget called 'draw' is created.
  116. draw = WIDGET_DRAW(base, $
  117.     /BUTTON_EVENTS, $    ;generate events when buttons pressed
  118.     /FRAME, $
  119.     UVALUE = 'DRAW_WIN_EVENT', $
  120.     RETAIN = 2, $        ;make sure draw is redrawn when covered
  121.     XSIZE = x_size, $
  122.     YSIZE = y_size)
  123.  
  124. ; Make a button which will erase the image.
  125. button2 = WIDGET_BUTTON(base, $
  126.         UVALUE = 'ERASE', $
  127.         VALUE = 'ERASE')
  128.  
  129. ; Make a button which will redisplay the image.
  130. button3 = WIDGET_BUTTON(base, $
  131.         UVALUE = 'REDRAW', $
  132.         VALUE = 'REDRAW')
  133.  
  134.  
  135. ; Realize the widgets:
  136. WIDGET_CONTROL, base, /REALIZE
  137.  
  138. ; Get the window number from the draw widget.  This can only be done
  139. ; after the widget has been realized.
  140. WIDGET_CONTROL, draw, GET_VALUE=win_num
  141.  
  142. ; Use TVSCL to display an image in the draw widget.  Set the window for
  143. ; the TVSCL command since there may be other draw windows.
  144. WSET, win_num
  145. orig_image = DIST(50)
  146. TVSCL, REBIN(orig_image, x_size, y_size)
  147.  
  148.  
  149. WSET, swin            ; Restore the original window
  150.  
  151. ; Set the common values for the image size
  152. x_im_sz = x_size
  153. y_im_sz = y_size
  154.  
  155. ; Hand off control of the widget to the XMANAGER:
  156. XMANAGER, "wdraw", base, GROUP_LEADER=GROUP, /NO_BLOCK
  157.  
  158.  
  159. END
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.